function Invoke-MultipleSQLScripts {
    param (
        [Parameter(Mandatory=$true)][string]$ServerName,
        [Parameter(Mandatory=$true)][string]$DatabaseName,
        [Parameter(Mandatory=$true)][pscredential]$Credential,
        [Parameter(Mandatory=$true)][string[]]$Files
    )

    $params = @{
        'ServerName' = $ServerName;
        'DatabaseName' = $DatabaseName;
        'Credential' = $Credential;
    }

    $errors = @{}

    # Invoke each file.
    foreach ($file in $Files) {
        try {
            Invoke-SQLScript @params -File $file
        }
        catch {
            $errors[$file] = $_
        }
    }

    if ($errors.Count -gt 0) {
        # Compress all error exceptions and their corresponding sql files into one message.
        throw "Failed to apply these scripts: $($errors.keys | ForEach-Object {"'$_' Message: $($errors[$_].Message), "})"
    }
}